package com.lmind.gps;

import java.net.InetSocketAddress;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.Log4jConfigurer;

import com.lmind.core.gps.publish.GpsPub;
import com.lmind.core.publish.SocketPublisherRouter;
import com.lmind.core.publish.Subscriber;

public class TmClient {
	
	public static void main(String[] args) {
		
		try {
			Log4jConfigurer.initLogging("classpath:override/log4j.xml");
			ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("client.xml");

			SocketPublisherRouter<GpsPub> gp = (SocketPublisherRouter<GpsPub>)context.getBean("socketPublisher");
			gp.connect(new InetSocketAddress("127.0.0.1", 15111));
			
			Thread.sleep(1000);
			
			gp.subscribe(new Subscriber<GpsPub>() {
				
				@Override
				public void feed(String name, GpsPub pub) {
					System.out.println(pub.getTerminal().getDeviceSerial());
				}
			}, "normal");
			
			
			Thread.sleep(10000000);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
